﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using System.Text;
using BLL;

namespace PMS.Web
{
    /// <summary>
    /// Menu 的摘要说明
    /// </summary>
    public class Menu : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string strAction = context.Request["action"];
            string strReturn = "";
            if (!string.IsNullOrEmpty(strAction))
            {
                System.Reflection.MethodInfo minfo = this.GetType().GetMethod(strAction);
                if (minfo != null)
                {
                    object o = minfo.Invoke(this, new object[] { context });
                    if (o != null)
                        strReturn = o.ToString();
                }
            }
            context.Response.Write(strReturn);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string DeleteMenu(HttpContext context)
        {
            string roleID = context.Request["roleID"];
            StringBuilder strHtml = new StringBuilder();
            BLL.PMS_RoleListBLL bll = new PMS_RoleListBLL();
            if (bll.Delete(Convert.ToInt32(roleID)))
            {
                return "0";
            }
            else
            {
                return "-1";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentID"></param>
        /// <returns></returns>
        public string GetList(HttpContext context)
        {
            string parentID = context.Request["parentID"];
            BLL.PMS_RoleListBLL bll = new PMS_RoleListBLL();
            List<PMS_RoleList> list = bll.GetList(parentID);
            StringBuilder strHtml = new StringBuilder();
            strHtml.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><th class=\"GridHeader\" width=\"8%\" align=\"center\">序号</th><th class=\"GridHeader\" width=\"12%\">名称</th><th class=\"GridHeader\" width=\"7%\">描述</th><th class=\"GridHeader\" width=\"4%\">编辑</th><th class=\"GridHeader\" width=\"5%\">删除</th></tr>");
            foreach (PMS_RoleList m in list)
            {
                strHtml.Append("<tr><td class=\"GridTableTD\" align=\"center\">" + m.roleValue + "</td><td class=\"GridTableTD\">" + m.roleText + "</td><td class=\"GridTableTD\">" + m.roleDescription + "</td><td class=\"GridTableTD\" style=\"cursor:pointer;\" onclick=\"editMenu(" + m.roleID + ")\">编辑</td><td class=\"GridTableTD\" style=\"cursor:pointer;\" onclick=\"deleteMenu(" + m.roleID + ")\">删除</td></tr>");
            }
            if (list == null || list.Count <= 0)
            {
                strHtml.Append("<tr><td colspan=\"5\" class=\"GridTableTD\" align=\"center\">没有数据</td></tr>");
            }
            strHtml.Append("</table>");
            return strHtml.ToString();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}